import { ref } from 'vue'
import pageModal from '../components/page-modal'
type CallbackFn = (item: []) => void
/*
像这样的方法导出一定要按顺序全部导出 不使用也要导出 因为它是按顺序与位置来识别方法的 要不然会使用不正常
*/
export default function (newCallback?: CallbackFn, editCallback?: CallbackFn) {
  const refPageModal = ref<InstanceType<typeof pageModal>>()
  const defaultInfo = ref({})
  //控制新建用户弹窗
  const handleNewClick = () => {
    defaultInfo.value = {}
    console.log('控制新建用户弹窗')
    if (refPageModal.value) {
      //对于不知道后面存在不存在的可以先判断
      refPageModal.value.dialogVisible = true
    }
    newCallback && newCallback([])
  }
  //控制编辑
  const handleeditClick = (event: any) => {
    defaultInfo.value = event
    console.log(event)
    if (refPageModal.value) {
      //对于不知道后面存在不存在的可以先判断
      refPageModal.value.dialogVisible = true
    }

    editCallback && editCallback(event.menuList)
  }
  return [refPageModal, defaultInfo, handleNewClick, handleeditClick]
}
